home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / lib / dl_vms.pro < prev    next >
Text File  |  1997-07-08  |  4KB  |  155 lines

  1. ; $Id: dl_vms.pro,v 1.3 1997/01/15 03:11:50 ali Exp $
  2. ;
  3. ; Copyright (c) 1982-1997, Research Systems, Inc.  All rights reserved.
  4. ;    Unauthorized reproduction prohibited.
  5. ;
  6.  
  7. pro DL_VMS, NAME, FILE=file, PRINT=printflg, PATH = path, $
  8.     NOFILEMSG=nofilemsg
  9. ;+NODOCUMENT
  10. ; NAME:
  11. ;    DL_VMS
  12. ;
  13. ; PURPOSE:
  14. ;    Extract the documentation template of one or more procedures.
  15. ;
  16. ; CATEGORY:
  17. ;    Help, documentation.
  18. ;
  19. ; CALLING SEQUENCE:
  20. ;    DL_VMS        ;For prompting.
  21. ;    DL_VMS, Name    ;Extract documentation for procedure Name using
  22. ;                the current !PATH.
  23. ;
  24. ; INPUTS:
  25. ;    Name:   A string containing the name of the procedure.
  26. ;
  27. ; KEYWORDS:
  28. ;    FILE:   If this keyword is set, the output is sent to the file
  29. ;        "userlib.doc", in the current directory.
  30. ;
  31. ;    PRINT:  If set, this keyword sends the  output of DL_VMS to lpr.
  32. ;
  33. ;    PATH:   An optional directory/library search path.  This keyword uses
  34. ;        the same format and semantics as !PATH.  If omitted, !PATH is
  35. ;        used.
  36. ; OUTPUTS:
  37. ;    Documentation is output to terminal or printer.
  38. ;
  39. ; COMMON BLOCKS:
  40. ;    None.
  41. ;
  42. ; SIDE EFFECTS:
  43. ;    Output is produced on terminal or printer.
  44. ;
  45. ; RESTRICTIONS:
  46. ;    None.
  47. ;
  48. ; PROCEDURE:
  49. ;    Straightforward.
  50. ;
  51. ; MODIFICATION HISTORY:
  52. ;    Written, DMS, Sept, 1982.
  53. ;    Added library param, Jul 1987.
  54. ;    Unix version, Feb, 1988.
  55. ;    Revised for VMS Version 2, 15 December 1989
  56. ;    Modified by Jim Pendleton, GRO/OSSE NU, July 30, 1992 to handle
  57. ;        !PATH's gt 255 characters.
  58. ;    AB, 21 September 1992, renamed from DOC_LIB_VMS to DL_VMS to
  59. ;        avoid DOS filename limitations.
  60. ;    ACY, 25 January 1993, file should be written with stream mode
  61. ;-
  62.  
  63. on_error,2             ;Return to caller if an error occurs
  64. params = n_params()
  65. if n_elements(path) eq 0 then path = !path
  66. do_print = keyword_set(printflg)
  67. to_file = keyword_set(file)
  68. do_filemsg = not keyword_set(nofilemsg)
  69. if (to_file) then del_file = 0 else del_file = 1
  70.  
  71. if n_elements(name) eq 0 then begin    ;Interactive query?
  72.   name = ''
  73.   printflg = 0
  74.   read,'Name of procedure: ',name
  75. endif
  76.  
  77. wild = name eq '*'         ;True for all modules
  78. ;  name = strlowcase(name)     ;make it always lower case
  79. name = strupcase(name)      ;make it always upper case
  80.  
  81. setlog,'_DOCUMENT',' ',table='LNM$JOB'  ;Logical name used for communic
  82. cmd_file = !dir + '[bin]doc_library' ;Name & locn of cmd proc
  83.  
  84. ;;cmd = '@'+ cmd_file + '  "[],'+path+'" '+name  ;To search curr directory
  85. ;;;; cmd = '@'+ cmd_file + '  "'+path+'" '+name  ;To omit current directory
  86. ;;spawn, cmd
  87.  
  88. ; Convert path into a string array, one path section per array element
  89. bpath = byte(path)
  90. comma = (byte(','))[0]
  91. loc = where(bpath eq comma, n_seg)
  92. if (n_seg eq 0) then begin
  93.   path_arr = path
  94. endif else begin
  95.   path_arr = strarr(n_seg + 1)
  96.   last = 0
  97.   for i = 0, n_seg-1 do begin
  98.     path_arr[i] = string(bpath[last:loc[i]-1])
  99.     last = loc[i]+1
  100.   endfor
  101.   path_arr[n_seg] = string(bpath[last:*])
  102. endelse
  103.  
  104.  
  105. ; Define the logical IDL_DL_PATH to be a multi-valued logical containing
  106. ; the value of path_arr
  107. for i = 0, n_elements(path_arr) - 1 do begin
  108.     setlog, 'IDL_DL_PATH_' + strtrim(i, 2), path_arr[i]
  109. endfor
  110.  
  111. ; Spawn the command file to do the searching
  112. spawn, '@'+ cmd_file + '  ' + name
  113. for i = 0, n_elements(path_arr) - 1 do begin
  114.     dellog, 'IDL_DL_PATH_' + strtrim(i, 2)
  115. endfor
  116. i = trnlog('_DOCUMENT', table='LNM$JOB', status)
  117. if status eq ' ' then message, 'Error executing command file ' + cmd_file
  118.  
  119. if status eq "?" then message, 'Module ' + name + ' not found in library.'
  120.  
  121. i = strpos(status,' ')      ;Found module, process
  122. in_name = strmid(status, 0, i)  ;Input file name
  123. to_delete = strmid(status, i+1,1) eq '1'  ;Delete input file flag
  124. source = strmid(status, i+3, 100)    ;Source file
  125.  
  126. if (to_file or do_print) then begin
  127.   openw,outunit,'userlib.doc', /GET_LUN, PRINT=do_print, DELETE=del_file, $
  128.      /STREAM
  129.   if (to_file and do_filemsg) then $
  130.     message, 'Documentation is in file "userlib.doc".', /INFORMATIONAL
  131. endif else begin
  132.   openw,outunit,'sys$output', /GET_LUN, /MORE
  133. endelse
  134.  
  135. if not wild then begin
  136.     printf, outunit, '---- Module: ', STRUPCASE(name), ' ----'
  137.     printf, outunit, '---- From:   ', source,'  -----'
  138.     endif
  139.  
  140. openr,inunit,in_name, /GET_LUN, delete=to_delete ;Read text file, delete when done
  141. A=''
  142. WHILE NOT EOF(inunit) DO BEGIN
  143.   READF,inunit,A
  144.   IF STRMID(A,0,2) EQ ';+' THEN BEGIN
  145.     READF,inunit,A
  146.     WHILE STRMID(A,0,2) NE ';-' DO BEGIN
  147.      PRINTF,outunit,STRMID(A,1,100) & READF,inunit,A
  148.      ENDWHILE
  149.     if not wild then goto, done else printf, outunit, " "
  150.     ENDIF
  151. ENDWHILE
  152.  
  153. done: FREE_LUN, inunit, outunit
  154. END
  155.